<?php
/**
 * Template for day weeks.
 * @author Ian Dunn <scholar42@gmail.com>
 * @version 1.0
 * @since 2013-11-20
 */
require_once 'login_info.php';
require_once 'schedule.php';

loginInfo::update_login ();

$week = $_GET['week'];

// load week variables.

$file = sprintf ("%s/week_%s.php", schedule::sched_dir(), $week);
include $file;

// will set $week_vars 

$year = 0;
$month = 0;
$d = 0;
list($year, $month, $d) = sscanf ($week, "%d_%d_%d");

$month_name = date("F", mktime(0,0,0,(int)$month,1,(int)$year));

$next_date = getdate(mktime(0,0,0,(int)$month,(int)$d+7,(int)$year));
$prev_date = getdate(mktime(0,0,0,(int)$month,(int)$d-7,(int)$year));

$next_file = sprintf("%d_%d_%d", (int)$next_date['year'], (int)$next_date['mon'], (int)$next_date['mday']);
$prev_file = sprintf("%d_%d_%d", (int)$prev_date['year'], (int)$prev_date['mon'], (int)$prev_date['mday']);

?>

<html>
	<head>
		<title>Opol - Schedule For Week of <?php print "$month/$d/$year";?> </title>
	</head>
	<body>
		<link rel="stylesheet" type="text/css" href="opol.css">
		<?php require 'menu.php'; ?>
		<br>
		<table border="1" class='sched'>
			<tr>
				<td class='sched_nav'><?php print "<a href='/view_week.php?week=$prev_file'>";?>&lt;</a></td>
				<td class='sched_name' colspan="5"><?php print "Week of $month_name $d, $year";?></td>
				<td class='sched_nav'><?php print "<a href='/view_week.php?week=$next_file'>";?>&gt;</td>
			</tr>

			<tr>
<?php
	$days_of_week = array ("Sun","Mon","Tues","Wed","Thurs","Fri","Sat");
	foreach ($days_of_week as $name) {
		print "\t\t\t\t<td>$name</td>\n";
	}
?>
			</tr>
			<tr>
<?php
if (isset ($GLOBALS['week_vars'])) {
	$week_vars = $GLOBALS['week_vars'];
}

foreach (range(0,6) as $day) {
	print "\t\t\t\t<td class='week_day'>\n";
	if (isset ($week_vars) && isset ($week_vars[$day])) {
		$day_vars = $week_vars[$day];
		if (isset ($day_vars) && count($day_vars) > 0) {
			print "\t\t\t\t\t<ul class='phase_list'>\n";
			foreach ($day_vars as $string) {
				print "\t\t\t\t\t\t<li>$string</li>\n";
			}
			print "\t\t\t\t\t</ul>\n";
		}
	}
	print "\t\t\t\t</td>\n";
}
?>
			<tr>
		</table>
	</body>
</html>
